package com.kiln.juxingqs.dialog

import android.content.Context
import android.widget.DatePicker
import com.kiln.juxingqs.R
import com.kiln.juxingqs.databinding.LayoutDatetimedialogBinding
import com.tzstore.oo.dialog.CenterDialog
import java.util.*

open class DateTimeDialog(context: Context) : CenterDialog<LayoutDatetimedialogBinding>(context) {

    var okTxt: String = "确定"
    var cancleTxt: String = "取消"
    var cancle: (() -> Unit)? = null
    var ok: ((year: Int, month: Int, day: Int) -> Unit)? = null


    fun okClick() {
        ok?.invoke(
            binding.datePicker.year,
            binding.datePicker.month + 1,
            binding.datePicker.dayOfMonth
        )
        cancel()
    }

    fun cancleClick() {
        cancle?.apply {
            this()
        }
        cancel()
    }

    override fun getV(): Int {
        return R.layout.layout_datetimedialog
    }

    override fun postBinding() {
        binding.event = this
        val calendar = Calendar.getInstance()
        binding.datePicker.init(
            calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH),
            object : DatePicker.OnDateChangedListener {
                override fun onDateChanged(
                    view: DatePicker?,
                    year: Int,
                    monthOfYear: Int,
                    dayOfMonth: Int
                ) {

                }

            }
        )
    }
}